package com.market.quote.modules.stock.domain.service;

import com.market.quote.modules.stock.domain.dto.StockInfoDTO;
import com.market.quote.modules.stock.domain.dto.StockRequestDTO;
import com.market.quote.modules.stock.domain.repository.StockRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author duweibin
 * @date 2024/4/22
 * @description com.market.quote.modules.stock.domain.service
 */
@Service
public class StockServiceImpl implements StockService{

    private final StockRepository stockRepository;

    @Autowired
    public StockServiceImpl(StockRepository stockRepository) {
        this.stockRepository = stockRepository;
    }

    @Override
    public StockInfoDTO getStockInfoById(Long id) {
        return stockRepository.getStockInfoById(id);
    }

    @Override
    public StockInfoDTO getStockInfo(StockRequestDTO stockRequestDTO) {
        return stockRepository.getStockInfoByDate(stockRequestDTO);
    }

    @Override
    public List<StockInfoDTO> getStockInfoList(StockRequestDTO stockRequestDTO) {
        return stockRepository.getStockInfoList(stockRequestDTO);
    }

    @Override
    public void saveStock(StockInfoDTO stockInfoDTO) {
        if(stockInfoDTO.getId() != null) {
            stockRepository.updateStock(stockInfoDTO);
        } else {
            stockRepository.insertStock(stockInfoDTO);
        }
    }

    @Override
    public void batchInsertStock(List<StockInfoDTO> stockInfoDTOList) {
        stockRepository.batchInsertStock(stockInfoDTOList);
    }

    @Override
    public void deleteStock(Long id) {
        stockRepository.deleteStock(id);
    }
}
